﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TankIt.Models.Math
{
    public static class Statistics
    {
        public static int Combinations(int NumberToChooseFrom, int NumberChosen)
        {
            //Combination formula
            //       n!
            //   ---------
            //    (n-r)!(r!)

            double nFact = Factorial(NumberToChooseFrom);
            double rFact = Factorial(NumberChosen);
            double nrFact = Factorial(NumberToChooseFrom - NumberChosen);

            double combination = nFact / (nrFact * rFact);

            return Convert.ToInt32(combination);

        }

        public static double Factorial(double number)
        {
            if (number <= 1)
                return 1;
            double fact = number * Factorial(number - 1);
            return fact;
        }
    }
}